<template>
  <div class="project">
    <XrHeader icon-class="wk wk-results-solid" icon-color="#2362FB" :showSearch="false" label="统计分析"/>
    <div v-loading="loading" class="project-body">
      <statistical-overview :data="detailData.taskStatistics" :list="detailData.ownerList" class="statistical-overview">
        <el-select v-model="workId" class="project-body-select" @change="getDetail">
          <el-option v-for="item in projectList" :key="item.workId" :label="item.name" :value="item.workId"/>
        </el-select>
      </statistical-overview>
      <flexbox v-if="workId != 'all'" class="statistical-task">
        <StatisticalTask :list="detailData.classStatistics" class="statistical-task-item"
                         type="task"
                         title="任务列表"/>
        <StatisticalTask :list="detailData.labelStatistics" class="statistical-task-item"
                         type="label"
                         title="标签分析"/>
      </flexbox>
      <StatisticalMember :list="detailData.memberTaskStatistics" class="statistical-member"/>
    </div>
  </div>
</template>

<script setup>
import {workIndexWorkListAPI} from '/src/api/pm/task.js'
import {workWorkStatisticAPI} from '/src/api/pm/statistics.js'

import StatisticalOverview from '/src/views/pm/components/StatisticalOverview.vue'
import StatisticalTask from '/src/views/pm/components/StatisticalTask.vue'
import StatisticalMember from '/src/views/pm/components/StatisticalMember.vue'
import XrHeader from '/src/components/XrHeader/index.vue'

const optionData = reactive({
  loading: false,
  detailData: {},
  projectList: [{workId: 'all', name: '全部'}],
  workId: 'all'
})

const {loading, detailData, projectList, workId} = toRefs(optionData)

function created() {
  getProjectList()
  getDetail()
}

created()

/**
 * 获取详情
 */
function getDetail() {
  optionData.loading = true
  workWorkStatisticAPI(optionData.workId).then(res => {
    optionData.detailData = res.data.data
    optionData.loading = false
  }).catch(() => {
    optionData.loading = false
  })
}

/**
 * 项目列表
 */
function getProjectList() {
  workIndexWorkListAPI().then(res => {
    optionData.projectList =
        [{workId: 'all', name: '全部'}].concat(res.data.data)
  }).catch(() => {
  })
}

</script>

<script>

export default {
  components: {
    // StatisticalOverview,
    // StatisticalTask,
    // StatisticalMember,
    // XrHeader
  },

  data() {
    return {}
  },


  methods: {}
}
</script>

<style lang="scss" scoped>
.project {
  height: 100%;
  overflow: hidden;
  user-select: none;
  position: relative;
}

.xr-header {
  padding-top: 0;
}

.project-body {
  position: absolute;
  top: 45px;
  right: 0;
  bottom: 0;
  left: 0;
  overflow-y: auto;

  .project-body-select {
    position: absolute;
    top: 8px;
    right: 8px;
  }
}

.statistical-overview {
  position: relative;
  background-color: white;
  border-radius: 3px;
  border: 1px solid #e6e6e6;
  overflow: hidden;
  padding-top: 5px;
}

.statistical-task {
  margin-top: 10px;

  .section {
    margin-top: 0;
  }

  .statistical-task-item {
    background-color: white;
    border-radius: 3px;
    border: 1px solid #e6e6e6;
    overflow: hidden;
    padding-top: 5px;
    flex: 1;
  }

  .statistical-task-item:first-child {
    margin-right: 10px;
  }
}

.statistical-member {
  background-color: white;
  border-radius: 3px;
  border: 1px solid #e6e6e6;
  overflow: hidden;
  padding-top: 5px;
}
</style>
